home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / ham / sattrk31.tgz / sattrack-3.1.tar / SatTrack / src / makepassesx / makepassesx.c
C/C++ Source or Header  |  1995-03-16  |  16KB  |  411 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Title       : makepassesx.c                                               */
  4. /*  Author      : Manfred Bester                                              */
  5. /*  Date        : 24Oct94                                                     */
  6. /*  Last change : 13Mar95                                                     */
  7. /*                                                                            */
  8. /*  Synopsis    : This program reads a satlist file and creates a C shell     */
  9. /*                script to run SatTrack in the batch mode for all satellites */
  10. /*                in the satlist file.                                        */
  11. /*                                                                            */
  12. /*  Usage       : makepassesx [group]                                         */
  13. /*                                                                            */
  14. /*  Input files : satlist_nnn.dat, batch.dat                                  */
  15. /*  Output file : passesx                                                     */
  16. /*                                                                            */
  17. /*                                                                            */
  18. /*  SatTrack is Copyright (c) 1992, 1993, 1994, 1995 by Manfred Bester.       */
  19. /*  All Rights Reserved.                                                      */
  20. /*                                                                            */
  21. /*  Permission to use, copy, and distribute SatTrack and its documentation    */
  22. /*  in its entirety for educational, research and non-profit purposes,        */
  23. /*  without fee, and without a written agreement is hereby granted, provided  */
  24. /*  that the above copyright notice and the following three paragraphs appear */
  25. /*  in all copies. SatTrack may be modified for personal purposes, but        */
  26. /*  modified versions may NOT be distributed without prior consent of the     */
  27. /*  author.                                                                   */
  28. /*                                                                            */
  29. /*  Permission to incorporate this software into commercial products may be   */
  30. /*  obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,    */
  31. /*  Berkeley, CA 94709, USA. Note that distributing SatTrack 'bundled' in     */
  32. /*  with ANY product is considered to be a 'commercial purpose'.              */
  33. /*                                                                            */
  34. /*  IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, */
  35. /*  SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF   */
  36. /*  THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED  */
  37. /*  OF THE POSSIBILITY OF SUCH DAMAGE.                                        */
  38. /*                                                                            */
  39. /*  THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT      */
  40. /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A   */
  41. /*  PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"      */
  42. /*  BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, */
  43. /*  UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                  */
  44. /*                                                                            */
  45. /******************************************************************************/
  46.  
  47. #include <stdio.h>
  48. #include <math.h>
  49. #include <string.h>
  50.  
  51. #ifndef STDLIB
  52. #include <stdlib.h>
  53. #endif
  54.  
  55. #include "sattrack.h"
  56.  
  57. #ifdef HPTERM
  58. #include "hpterm.h"
  59. #else
  60. #include "vt100.h"
  61. #endif
  62.  
  63. /******************************************************************************/
  64. /*                                                                            */
  65. /* definitions of default command line arguments                              */
  66. /* these will be used if a particular argument is unspecified in 'batch.dat'  */
  67. /*                                                                            */
  68. /******************************************************************************/
  69.  
  70. #define  SATTRACK     "sattrack"
  71. #define  ARGUMENT     "-b"
  72. #define  TIMEZONEX    "PDT"
  73. #define  SITENAME     "Mt._Wilson"
  74. #define  TLEFILE      "tlex.dat"
  75. #define  TLETYPE      "NASA"
  76. #define  PREDTYPE     "shortpr"
  77. #define  STARTDATE    "now"
  78. #define  STARTTIME    "now"
  79. #define  TIMESTEP     "auto"
  80. #define  DURATION     "7"
  81. #define  MINELEV      "0"
  82. #define  HARDCOPYX    "nohardcopy"
  83.  
  84. /******************************************************************************/
  85. /*                                                                            */
  86. /* external functions                                                         */
  87. /*                                                                            */
  88. /******************************************************************************/
  89.  
  90. extern void clipString(), fillBlanks(), mGets(), truncBlanks(), upperCase();
  91.  
  92. /******************************************************************************/
  93. /*                                                                            */
  94. /* main program                                                               */
  95. /*                                                                            */
  96. /******************************************************************************/
  97.  
  98. void main(argc,argv)
  99.  
  100. int  argc;
  101. char *argv[];
  102.  
  103. {
  104.     char satListName[100], sysComm[120], data[100], run[100], satGroup[10];
  105.     char batchStr[120], inputSatFile[100], outputFile[100], resourceFile[100];
  106.     char resourceLine[120];
  107.     char arg0[40], arg1[40], arg2[40], arg3[40], arg4[40], arg5[40], arg6[40];
  108.     char arg7[40], arg8[40], arg9[40], arg10[40], arg11[40], arg12[40];
  109.     char arg13[40];
  110.     char *strpHome, *getenv();
  111.  
  112.     FILE *InputSatFile, *OutputFile, *ResourceFile;
  113.  
  114. /******************************************************************************/
  115. /*                                                                            */
  116. /* check home directory                                                       */
  117. /*                                                                            */
  118. /******************************************************************************/
  119.  
  120. #ifdef HOMEDIR
  121.     strpHome = getenv("HOME");
  122. #else
  123.     strpHome = SATDIR;
  124. #endif
  125.  
  126. /******************************************************************************/
  127. /*                                                                            */
  128. /* check command line arguments and make file names                           */
  129. /*                                                                            */
  130. /******************************************************************************/
  131.  
  132.     if (argc == 2)
  133.     {
  134.         strcpy(satGroup,argv[1]);
  135.     }
  136.  
  137.     else
  138.     {
  139.         printf("\nenter satellite group (am,com,gps,mir,sci,tv,wx,etc.) : ");
  140.         mGets(satGroup);
  141.     }
  142.  
  143.     sprintf(data,"%s/%s",strpHome,DATA);
  144.     sprintf(run,"%s/%s",strpHome,RUN);
  145.  
  146.     sprintf(resourceFile,"%s/batch.dat",data);
  147.     sprintf(inputSatFile,"%s/satlist_%s.dat",data,satGroup);
  148.     sprintf(outputFile,"%s/passesx",run);
  149.  
  150. /******************************************************************************/
  151. /*                                                                            */
  152. /* check if files are accessible                                              */
  153. /*                                                                            */
  154. /******************************************************************************/
  155.  
  156.     if ((ResourceFile = fopen(resourceFile,"r")) == NULL)
  157.     {
  158.         nl(); doBeep(); reverseBlink();
  159.         printf("%s not found\n",resourceFile);
  160.         normal(); nl();
  161.         exit(-1);
  162.     }
  163.  
  164.     if ((InputSatFile = fopen(inputSatFile,"r")) == NULL)
  165.     {
  166.         nl(); doBeep(); reverseBlink();
  167.         printf("%s not found\n",inputSatFile);
  168.         normal(); nl();
  169.         exit(-1);
  170.     }
  171.  
  172.     if ((OutputFile = fopen(outputFile,"w")) == NULL)
  173.     {
  174.         nl(); doBeep(); reverseBlink();
  175.         printf("can't write %s\n",outputFile);
  176.         normal(); nl();
  177.         exit(-1);
  178.     }
  179.  
  180. /******************************************************************************/
  181. /*                                                                            */
  182. /* load default parameters                                                    */
  183. /*                                                                            */
  184. /******************************************************************************/
  185.  
  186.     sprintf(arg0, "%s",SATTRACK);
  187.     sprintf(arg1, "%s",ARGUMENT);
  188.     sprintf(arg2, "%s",TIMEZONEX);
  189.     sprintf(arg3, "%s",SITENAME);
  190.  
  191.     sprintf(arg5, "%s",TLEFILE);
  192.     sprintf(arg6, "%s",TLETYPE);
  193.     sprintf(arg7, "%s",PREDTYPE);
  194.     sprintf(arg8, "%s",STARTDATE);
  195.     sprintf(arg9, "%s",STARTTIME);
  196.     sprintf(arg10,"%s",TIMESTEP);
  197.     sprintf(arg11,"%s",DURATION);
  198.     sprintf(arg12,"%s",MINELEV);
  199.     sprintf(arg13,"%s",HARDCOPYX);
  200.  
  201. /******************************************************************************/
  202. /*                                                                            */
  203. /* read resource file 'batch.dat'                                             */
  204. /*                                                                            */
  205. /******************************************************************************/
  206.  
  207.     while (fgets(resourceLine,100,ResourceFile))
  208.     {
  209.         resourceLine[strlen(resourceLine) - 1] = '\0';
  210.         truncBlanks(resourceLine);
  211.  
  212.         sscanf(resourceLine,"Time zone: %s",arg2);
  213.  
  214.         if (!strncmp(resourceLine,"Site:",5))
  215.         {
  216.             clipString(resourceLine,5);
  217.             sprintf(arg3,"%s",resourceLine);
  218.             upperCase(arg3);
  219.             fillBlanks(arg3);
  220.         }
  221.  
  222.         sscanf(resourceLine,"Element set TLE: %s",arg5);
  223.         sscanf(resourceLine,"Element set type: %s",arg6);
  224.         sscanf(resourceLine,"Prediction type: %s",arg7);
  225.         sscanf(resourceLine,"Start date: %s",arg8);
  226.         sscanf(resourceLine,"Start time: %s",arg9);
  227.         sscanf(resourceLine,"Time step: %s",arg10);
  228.         sscanf(resourceLine,"Duration: %s",arg11);
  229.         sscanf(resourceLine,"Min elevation: %s",arg12);
  230.         sscanf(resourceLine,"Hardcopy: %s",arg13);
  231.     }
  232.  
  233.     fclose(ResourceFile);
  234.  
  235. /******************************************************************************/
  236. /*                                                                            */
  237. /* create the C shell script 'passesx'                                        */
  238. /*                                                                            */
  239. /******************************************************************************/
  240.  
  241.     fprintf(OutputFile,"#! /bin/csh\n");
  242.     fprintf(OutputFile,"#\n");
  243.     fprintf(OutputFile,"# passesx\n");
  244.     fprintf(OutputFile,"#\n");
  245.     fprintf(OutputFile,"# ATTENTION: this C shell script is subject to ");
  246.     fprintf(OutputFile,"automatic regeneration by 'makepassesx'.\n");
  247.     fprintf(OutputFile,"#\n");
  248.  
  249.     while (fgets(satListName,80,InputSatFile))
  250.     {
  251.         satListName[strlen(satListName)-1] = '\0';
  252.         upperCase(satListName);
  253.         fillBlanks(satListName);
  254.         sprintf(arg4,"%s",satListName);
  255.  
  256.         sprintf(batchStr,"%s  %s",arg0,arg1);
  257.         sprintf(batchStr,"%s  %s",batchStr,arg2);
  258.         sprintf(batchStr,"%s  %s",batchStr,arg3);
  259.         sprintf(batchStr,"%s  %-11s",batchStr,arg4);
  260.         sprintf(batchStr,"%s  %s",batchStr,arg5);
  261.         sprintf(batchStr,"%s  %s",batchStr,arg6);
  262.         sprintf(batchStr,"%s  %s",batchStr,arg7);
  263.         sprintf(batchStr,"%s  %s",batchStr,arg8);
  264.         sprintf(batchStr,"%s  %s",batchStr,arg9);
  265.         sprintf(batchStr,"%s  %s",batchStr,arg10);
  266.         sprintf(batchStr,"%s  %s",batchStr,arg11);
  267.         sprintf(batchStr,"%s  %s",batchStr,arg12);
  268.         sprintf(batchStr,"%s  %s",batchStr,arg13);
  269.  
  270.         fprintf(OutputFile,"  %s\n",batchStr);
  271.     }
  272.  
  273.     fclose(InputSatFile);
  274.     fclose(OutputFile);
  275.  
  276.     sprintf(sysComm,"chmod 755 %s",outputFile);
  277.     system(sysComm);
  278. }
  279.  
  280. /******************************************************************************/
  281. /*                                                                            */
  282. /* clipString: clips N characters plus leading blanks off the beginning of a  */
  283. /*             character string                                               */
  284. /*                                                                            */
  285. /******************************************************************************/
  286.  
  287. void clipString(charStr,N)
  288.  
  289. int  N;
  290. char *charStr;
  291.  
  292. {
  293.     int  i, j, firstChar;
  294.     char tmpStr[100];
  295.  
  296.     firstChar = FALSE;
  297.     j = 0;
  298.  
  299.     for (i = 0; i < strlen(charStr) - N; i++) 
  300.     {
  301.  
  302.        if (charStr[i+N] != ' ' || (charStr[i+N] == ' ' && firstChar))
  303.        {
  304.            tmpStr[j] = charStr[i+N];
  305.            j++;
  306.            firstChar = TRUE;
  307.        }
  308.     }
  309.  
  310.     tmpStr[j] = '\0';                            /* add termination character */
  311.     sprintf(charStr,"%s",tmpStr);
  312.     return;
  313. }
  314.  
  315. /******************************************************************************/
  316. /*                                                                            */
  317. /* fillBlanks: replaces blank characters by underscore characters             */
  318. /*                                                                            */
  319. /******************************************************************************/
  320.  
  321. void fillBlanks(charStr)
  322.  
  323. char *charStr;
  324.  
  325. {
  326.     int  i;
  327.  
  328.     for (i = 0; i < strlen(charStr); i++)
  329.     {
  330.         if (charStr[i] == ' ')
  331.             charStr[i] = '_';
  332.     }
  333.  
  334.     return;
  335. }
  336.  
  337. /******************************************************************************/
  338. /*                                                                            */
  339. /* truncBlanks: truncates trailing blanks from character string               */
  340. /*                                                                            */
  341. /******************************************************************************/
  342.  
  343. void truncBlanks(string)
  344.  
  345. char *string;
  346.  
  347. {
  348.     int i;
  349.  
  350.     i = strlen(string) - 1;
  351.  
  352.     while (string[i] == ' ')
  353.     {
  354.         i--;
  355.     }
  356.  
  357.     string[i+1] = '\0';                          /* add termination character */
  358.     return;
  359. }
  360.  
  361. /******************************************************************************/
  362. /*                                                                            */
  363. /* upperCase: changes lower to upper case letters                             */
  364. /*                                                                            */
  365. /******************************************************************************/
  366.  
  367. void upperCase(string)
  368.  
  369. char *string;
  370.  
  371. {
  372.     int i;
  373.  
  374.     for (i = 0; i < strlen(string); i++)
  375.     {
  376.         if (string[i] >= 'a' && string[i] <= 'z')
  377.             string[i] -= 'a' - 'A';
  378.     }
  379.  
  380.     return;
  381. }
  382.  
  383. /******************************************************************************/
  384. /*                                                                            */
  385. /* mGets: Manfred's version of fgets (wipes out newline character)            */
  386. /*                                                                            */
  387. /******************************************************************************/
  388.  
  389. void mGets(string)
  390.  
  391. char *string;
  392.  
  393. {
  394.     int i;
  395.     fgets(string,80,stdin);
  396.     i = (int) strlen(string);
  397.  
  398.     if (i > 0)
  399.         string[i-1] = '\0';
  400.     else
  401.         string[0]   = '\0';
  402.  
  403.     return;
  404. }
  405.  
  406. /******************************************************************************/
  407. /*                                                                            */
  408. /* End of program makepassesx.c                                               */
  409. /*                                                                            */
  410. /******************************************************************************/
  411.